<?php
namespace Home\Controller;
use Common\Controller\CommonController;
class IndexController extends CommonController {
	protected function _initialize() {

		parent::_initialize();

        if(is_login()){

        	redirect(U('/customer'));

        }

    }
    public function index(){

    	if(IS_POST){

    		$username = I('request.username' , '' , 'htmlspecialchars');

    		$password = I('request.password' , '' , 'htmlspecialchars');

    		$verification = I('request.verification' , '' , 'htmlspecialchars');

    		if(empty($username)){
    			$this->error('用户名不能为空');
    		}
    		if(empty($password)){
    			$this->error('登录密码不能为空');
    		}
    		if(empty($verification)){
    			$this->error('验证码不能为空');
    		}elseif(!A('Home/Public')->checkVerify($verification)){
    			$this->error('验证码错误');
    		}
    		
    		$result = $this->login($username , $password);

    		if($result === true){

    			$this->success('登录成功！');

    		}else{

    			$this->error($result['message']?$result['message']:'登录失败！');

    		}

    	}
    	
    	$this->display();

    }
}